var path = require('path')
var webpack = require('webpack')
var fs = require("fs")
const VueLoaderPlugin = require('vue-loader/lib/plugin');
var HtmlWebpackPlugin = require('html-webpack-plugin');

function read(path){
    return fs.readFileSync(path,{encoding:"utf-8"})
}

var markdown = read("./test.md")

module.exports = {
    mode:'development',
    externals:{
        prismjs:'Prism'
    },
  entry: './src/main.js',
    node:{
        fs:'empty'
    },
  output: {
    path: path.resolve(__dirname, './dist'),
    publicPath: '/',
    filename: 'build.js'
  },
  module: {
    rules: [
      {
        test: /\.vue$/,
        loader: 'vue-loader',
        options: {
          loaders: {
          }
          // other vue-loader options go here
        }
      },
      {
        test: /\.css$/,
        use: ['style-loader', 'css-loader']
      },
      {
        test: /\.js$/,
        loader: 'babel-loader',
        exclude: /node_modules/
      },
      {
        test: /\.(gif|jpg|png|woff|svg|eot|ttf)\??.*$/,
        loader: 'url-loader?limit=1024'
      }
    ]
  },
  resolve: {
      alias: {
          'vue$': 'vue/dist/vue.esm.js',
      },
      extensions:['.js', '.vue']
  },
  devServer: {
    historyApiFallback: true,
    overlay: true
  },
  performance: {
    hints: false
  },
  devtool: '#eval-source-map'
}

if (process.env.NODE_ENV === 'production') {
  module.exports.devtool = '#source-map'
  // http://vue-loader.vuejs.org/en/workflow/production.html
  module.exports.plugins = (module.exports.plugins || []).concat([
    new webpack.DefinePlugin({
      'process.env': {
        NODE_ENV: '"production"'
      }
    }),
    new webpack.optimize.UglifyJsPlugin({
      sourceMap: true,
      compress: {
        warnings: false
      }
    }),
    new webpack.LoaderOptionsPlugin({
      minimize: true
    })
  ])
}
else
  module.exports.plugins = (module.exports.plugins || []).concat([
      new VueLoaderPlugin(),
      new HtmlWebpackPlugin({
          title:'Rmarkdown',
          template: path.join(__dirname,'../src/index.html'), //模板地址
          filename:'index.html'
      }),
      new webpack.DefinePlugin({
          MARKDOWN:JSON.stringify(markdown)
      })
  ])
